//
//  TZL_NavView.m
//  MyTabbarDemo
//
//  Created by Yuki on 2021/10/11.
//

#import "TZL_NavView.h"
#import "TZL_SystemApiConfig.h"
#import <Masonry.h>

@interface TZL_NavView ()
/**  返回按钮  **/
@property (nonatomic , strong)UIButton  *backBtn;

/**  标题  **/
@property (nonatomic , strong)UILabel  *titleLb;

/**  底部横线  **/
@property (nonatomic , strong)UIView  *bottomLine;
@end

@implementation TZL_NavView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self buildUI];
    }
    return self;
}


#pragma mark - --------- 设置界面  ---------
- (void)buildUI{
    self.backgroundColor = UIColor.whiteColor;
    //返回按钮
    [self addSubview:self.backBtn];
    //返回按钮距离底部为2
//    self.backBtn.frame = CGRectMake(15, TZL_NavgationHeight() - 46, 44, 44);
    [self.backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.size.mas_equalTo(CGSizeMake(44, 44));
        make.bottom.mas_equalTo(-2);
    }];
    [self.backBtn addTarget:self action:@selector(backBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
    [self addSubview:self.titleLb];
    [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.height.mas_equalTo(20);
        make.centerY.mas_equalTo(self.backBtn);
    }];
    
    [self addSubview:self.bottomLine];
    [self.bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.height.mas_equalTo(1.0f);
    }];

}
#pragma mark - --------- set方法  ---------
- (void)setTitleStr:(NSString *)titleStr{
    _titleStr = titleStr;
    self.titleLb.text = titleStr;
}

/// 是否显示返回按钮
/// @param showBackBtn YES为显示，NO为不显示
- (void)setShowBackBtn:(BOOL)showBackBtn{
    _showBackBtn = showBackBtn;
    self.backBtn.hidden = !showBackBtn;
}


/// 点击返回按钮
- (void)backBtnClick{
    if (self.clickBackBtnBlock) {
        self.clickBackBtnBlock();
    }
}

#pragma mark - --------- lazy  ---------
/// 返回按钮
- (UIButton *)backBtn{
    if (!_backBtn) {
        _backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_backBtn setImage:[UIImage imageNamed:@"return_left40"] forState:UIControlStateNormal];
    }
    return _backBtn;
}


/// 标题
- (UILabel *)titleLb{
    if (!_titleLb) {
        _titleLb = UILabel.new;
        _titleLb.font = [UIFont systemFontOfSize:17 weight:UIFontWeightMedium];
        _titleLb.textColor = UIColor.blackColor;
        _titleLb.textAlignment = NSTextAlignmentCenter;
    }
    return _titleLb;
}

/// 底部横线
- (UIView *)bottomLine{
    if (!_bottomLine) {
        _bottomLine = [UIView new];
        _bottomLine.backgroundColor = ColorHex(0xf5f5f5, 1);
    }
    return _bottomLine;
}
@end
